

//
//  YKStatusFrame.m
//  youkan
//
//  Created by mac mini on 16/3/3.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKStatusFrame.h"
#import "YKWBStatues.h"
#import "YKUser.h"
@implementation YKStatusFrame
-(void)setStatus:(YKWBStatues *)status{
    _status =status;
    [self setUpOriginalViewFram];
    CGFloat toolBarX =0;
    CGFloat toolBarY=CGRectGetMaxY(_originalF);
    if (status.retweeted_status) {
        [self setUpRetweetViewFram];
        toolBarY =CGRectGetMaxY(_retweetF);
    }
    _toolBarF =CGRectMake(toolBarX, toolBarY, SCWidth, 35);
    _cellHeight =CGRectGetMaxY(_toolBarF);
}
//    计算原创微博
-(void)setUpOriginalViewFram{
//    头像
    CGFloat imaX =YKStatusCellMargin;
    CGFloat imaY = imaX;
    CGFloat imaWH =35;
    _oriIconF =CGRectMake(imaX, imaY, imaWH, imaWH);
//    昵称
    CGFloat nameX =CGRectGetMaxX(_oriIconF)+YKStatusCellMargin;
    CGFloat nameY=imaY;
//    CGSize nameSize =[_status.user.name sizeWithFont:YKNameFont];
    CGSize nameSize =[_status.user.name sizeWithAttributes:@{NSFontAttributeName:YKNameFont}];
    _oriNameF =(CGRect){{nameX,nameY},nameSize};
    if (_status.user.vip) {
        CGFloat vipX=CGRectGetMaxX(_oriNameF)+YKStatusCellMargin;
        CGFloat vipY=nameY;
        CGFloat vipWH =14;
        _oriVIPF =CGRectMake(vipX, vipY, vipWH, vipWH);
    }

    
//    时间
//    CGFloat timeX = nameX;
//    CGFloat timeY = CGRectGetMaxY(_oriNameF)+YKStatusCellMargin*0.5;
//    CGSize timeSize =[_status.created_at sizeWithFont:YKTimeFont];
//    _oriTimeF =(CGRect){{timeX,timeY},timeSize};
//来源
//    CGFloat sourceX =CGRectGetMaxX(_oriTimeF)+YKStatusCellMargin;
//    CGFloat sourceY = timeY;
//    CGSize sourceSize =[_status.source sizeWithFont:YKSouresFont];
//    _oriSourceF =    (CGRect){{sourceX,sourceY},sourceSize};
//正文

    CGFloat textX =imaX;
    CGFloat textY=CGRectGetMaxY(_oriIconF)+YKStatusCellMargin;
    CGFloat textW =SCWidth -2*YKStatusCellMargin;
//    CGSize textSize =[_status.text sizeWithFont:YKTextFont constrainedToSize:CGSizeMake(textW ,MAXFLOAT)];
    CGSize textSize =[_status.text boundingRectWithSize:CGSizeMake(textW ,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:YKTextFont} context:nil].size;
    _oriTextF =(CGRect){{textX,textY},textSize};
    CGFloat originH=CGRectGetMaxY(_oriTextF)+YKStatusCellMargin;

    //配图
    if (_status.pic_urls.count) {
        CGFloat x=YKStatusCellMargin;
        CGFloat y =CGRectGetMaxY(_oriTextF)+YKStatusCellMargin ;
        CGSize photosViesSize =[self photoSizeWithCount:_status.pic_urls.count];
        _oriPhtotsF =(CGRect){{x,y},photosViesSize};
       originH=CGRectGetMaxY(_oriPhtotsF)+YKStatusCellMargin;

    }
    CGFloat originX=0;
#warning 控制cell间的间距
    CGFloat originY =0;
    CGFloat originW=SCWidth;
    _originalF =CGRectMake(originX, originY, originW, originH);

}
//    计算转发微博
-(void)setUpRetweetViewFram{
    //    昵称
    CGFloat nameX =YKStatusCellMargin;
    CGFloat nameY=nameX;
//    CGSize nameSize =[_status.retweetName sizeWithFont:YKNameFont];
    CGSize nameSize =[_status.retweetName sizeWithAttributes:@{NSFontAttributeName:YKNameFont}];
    _retNameF =(CGRect){{nameX,nameY},nameSize};
//    正文
    //正文

    CGFloat textX =nameX;
    CGFloat textY=CGRectGetMaxY(_retNameF)+YKStatusCellMargin;
    CGFloat textW =SCWidth -2*YKStatusCellMargin;
//    CGSize textSize =[_status.retweeted_status.text sizeWithFont:YKTextFont constrainedToSize:CGSizeMake(textW ,MAXFLOAT)];
    CGSize textSize =[_status.retweeted_status.text boundingRectWithSize:CGSizeMake(textW ,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:YKTextFont} context:nil].size;
    _retTextF =(CGRect){{textX,textY},textSize};
    CGFloat retweetH = CGRectGetMaxY(_retTextF)+YKStatusCellMargin;

    NSInteger count =_status.retweeted_status.pic_urls.count;
    if (count) {
        CGFloat x=YKStatusCellMargin;
        CGFloat y =CGRectGetMaxY(_retTextF)+YKStatusCellMargin ;
        CGSize photosViesSize =[self photoSizeWithCount:count];
        _retPhotF =(CGRect){{x,y},photosViesSize};
        retweetH=CGRectGetMaxY(_retPhotF)+YKStatusCellMargin;
    }
    
    CGFloat retweetX=0;
    CGFloat retweetY=CGRectGetMaxY(_originalF);
    CGFloat retweetW=SCWidth;
    _retweetF =CGRectMake(retweetX, retweetY, retweetW, retweetH);
}
-(CGSize)photoSizeWithCount:(NSInteger)count{
    NSInteger cols =count ==4?2:3;
    NSInteger row =(count-1)/cols+1 ;
    CGFloat photosWH =70;
    CGFloat w=cols*photosWH+(cols-1)*YKStatusCellMargin;
    CGFloat h =row*photosWH+(row-1)*YKStatusCellMargin;
    return CGSizeMake(w, h);
}
//    计算工具条
-(void)setUpToolBarViewFram{
    
}

//      计算cell高度
-(void)setUpRowHeight{
    
}

@end
